package com.newtouch.bxzs.business.train.mapper;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.business.train.model.bo.ExaminationUserBO;
import com.newtouch.bxzs.common.base.model.ExaminationUserMap;

/**
 * 参考人员和考试对应关系mapper
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/21</td>
 * <td>lanwei</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author lanwei
 * @version 1.0.0
 * @since 1.0.0
 */
@Mapper
public interface ExaminationUserMapMapper extends BaseMapper<ExaminationUserMap> {

    /**
     * 根据考试Id查询参考人员列表
     * @param examinationId
     * @return
     */
    @Select("select EXAMINATION_USER_MAP_ID examinationUserMapId, USER_ID userId " +
            " from ASSISTANT_EXAMINATION_USER_MAP where IS_DELETE = 0 and EXAMINATION_ID=#{examinationId}")
    List<Map<String,Object>> getExaminationUserIdListByExaminationId(@Param("examinationId") String examinationId);


//    /**
//     * 查看所有考试人员列表
//     * @param examinationId 考试id
//     * @param userOrganizationCode 组织机构代码
//     * @return
//     */
//    @Select("select u.USER_ID userId,u.USER_JOB_NUMBER userJobNumber,u.USER_NAME userName," +
//            " u.USER_SEX userSex,u.USER_PHONE userPhone,u.USER_ORGANIZATION_NAME userOrganizationName," +
//            " u.USER_DEPARTMENT_NAME userDepartmentName,u.USER_LOGIN_PASSWORD userLoginPassword,\n" +
//            " if(e.EXAMINATION_ID is null,0,1) isChecked\n" +
//            " from ASSISTANT_USER u \n" +
//            " inner join ASSISTANT_USER_POSITION_MAP p on u.USER_ID=p.USER_ID and u.IS_DELETE=0 and u.USER_ORGANIZATION_CODE=#{userOrganizationCode}\n" +
//            " INNER JOIN ASSISTANT_ROLE_POSITION_MAP p2 on p.POSITION_ID=p2.POSITION_ID \n" +
//            " inner join ASSISTANT_ROLE r on p2.ROLE_ID=r.ROLE_ID and r.IS_DELETE=0 and r.TERMINAL_TYPE=1\n" +
//            " left join ASSISTANT_EXAMINATION_USER_MAP e on e.USER_ID=u.USER_ID and e.IS_DELETE=0 and e.EXAMINATION_ID=#{examinationId}" +
//            " limit #{startPage},#{endPage}")
//    List<ExaminationUserBO> getExaminationUserList(@Param("examinationId") String examinationId, @Param("userOrganizationCode") String userOrganizationCode, @Param("startPage") Integer startPage, @Param("endPage") Integer endPage);

    /**
     * 查看所有考试人员列表
     * @param examinationId
     * @param startPage
     * @param endPage
     * @return
     */
    IPage<ExaminationUserBO> getExaminationUserList(@Param("examinationId") String examinationId, @Param("page")Page<ExaminationUserBO> page);

    
    
    
//    /**
//     * 查看考试人员总数
//     * @param examinationId
//     * @param userOrganizationCode
//     * @return
//     */
//    @Select("select count(1)" +
//            " from ASSISTANT_USER u \n" +
//            " inner join ASSISTANT_USER_POSITION_MAP p on u.USER_ID=p.USER_ID and u.IS_DELETE=0 and u.USER_ORGANIZATION_CODE=#{userOrganizationCode}\n" +
//            " INNER JOIN ASSISTANT_ROLE_POSITION_MAP p2 on p.POSITION_ID=p2.POSITION_ID \n" +
//            " inner join ASSISTANT_ROLE r on p2.ROLE_ID=r.ROLE_ID and r.IS_DELETE=0 and r.TERMINAL_TYPE=1\n" +
//            " left join ASSISTANT_EXAMINATION_USER_MAP e on e.USER_ID=u.USER_ID and e.IS_DELETE=0  and e.EXAMINATION_ID=#{examinationId}")
//    Integer getExaminationUserListTotal(@Param("examinationId") String examinationId,@Param("userOrganizationCode") String userOrganizationCode);

    /**
     * 查看考试人员总数
     * @param examinationId
     * @return
     */
    @Select("select count(1) from ASSISTANT_USER u")
    Integer getExaminationUserListTotal(@Param("examinationId") String examinationId);
    
}
